//
//  GDViewController.m
//  WeiDuYY
//
//  Created by 王克杨的Mac on 2019/1/23.
//  Copyright © 2019 W ke杨. All rights reserved.
//

#import "GDViewController.h"
#import "ViewController.h"
#import <SDAutoLayout.h>
#import "LgViewController.h"
#define HCWidth self.view.frame.size.width
#define HCHeight self.view.frame.size.height
@interface GDViewController ()<UIScrollViewDelegate>
{
    UIScrollView *sc; // 滚动视图
    UIPageControl *pageC; // 分页控制符
    NSArray *imgArr; // 图片数组
}

@end
@implementation GDViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    // 滚动视图
    sc = [[UIScrollView alloc]initWithFrame:self.view.frame];
    // 设置滚动视图的代理
    sc .delegate = self;
    // 滚动范围
    sc.contentSize = CGSizeMake(4 * HCWidth,0);
    // 分页
    sc.pagingEnabled = YES;
    // 弹簧
    sc.bounces = NO;
    // 禁用水平滚动条
    sc.showsHorizontalScrollIndicator = NO;
    sc.showsVerticalScrollIndicator=NO;
    // 将滚动视图添加
    sc.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:sc];
    
    // 添加图片
    for (int i = 0; i < 4; i++){
        
        
        UIView *view=[[UIView alloc]init];
        //        view.backgroundColor=[UIColor blueColor];
        [sc addSubview:view];
        view.sd_layout.topSpaceToView(sc, 0).leftSpaceToView(sc, i*HCWidth).widthIs(self.view.frame.size.width).heightIs(self.view.frame.size.height);
        imgArr = @[@"图层1",@"图层2",@"图层3",@"icon"];
        // 图片
        UIImageView *imgV = [[UIImageView alloc]init];
        imgV.image = [UIImage imageNamed:imgArr[i]];
        
        // 设置用户交互属性
        imgV.userInteractionEnabled = YES;
        // 滚动视图添加图片
        [view addSubview:imgV];
        imgV.sd_layout.topSpaceToView(view, 150).leftSpaceToView(view, 80).widthIs(250).heightIs(250);
        NSArray *arr=@[@"\t一场电影\n\n 净化你的灵魂",@"\t一场电影\n\n 看遍人生百态",@"\t一场电影\n\n 荡涤你的心灵",@"带您开启一段\n\n美好的电影之旅"];
        UILabel *lab=[UILabel new];
        lab.numberOfLines=0;
        lab.text=arr[i];
        lab.textColor=[UIColor colorWithRed:144/255.0 green:145/255.0 blue:145/255.0 alpha:1.0];
        [view addSubview:lab];
        lab.sd_layout.topSpaceToView(view, 400).leftSpaceToView(view, 150).widthIs(250).heightIs(200);
        //添加手势
        if (i==3) {
            UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(event:)];
            //将手势添加到需要相应的view中去
            
            [view addGestureRecognizer:tapGesture];
            //选择触发事件的方式（默认单机触发）
            
            [tapGesture setNumberOfTapsRequired:1];
        }
        
        
        
    }
  
        
     

    


    // 豆豆
    pageC = [[UIPageControl alloc]init];
    
    // 豆豆的数量
    pageC.numberOfPages = imgArr.count;
    // 豆豆颜色
    pageC.pageIndicatorTintColor = [UIColor blackColor];
    pageC.currentPageIndicatorTintColor = [UIColor orangeColor];
    // 默认选中
    pageC.currentPage = 0;
    //将豆豆往滚动视图里加
    [self.view addSubview:pageC];
    pageC.sd_layout.topSpaceToView(self.view, 660).leftSpaceToView(self.view,(HCWidth - 200)/2 ).widthIs(200).heightIs(40);
    
    
}





-(void)event:(UITapGestureRecognizer *)gesture{
    LgViewController *lg=[LgViewController new];
    [self presentViewController:lg animated:YES completion:nil];

}



// 视图已经滚动的方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    pageC.currentPage = sc.contentOffset.x/HCWidth;
    
}

@end
